<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2>车辆质量投诉问题</h2>
<div>
    <form method="post" action="/veh/list" th:action="@{/veh/list}">
    品牌：<select name="brandId" id="brandId">
    <option value="0">请选择</option>
</select>
    <input type="submit" value="查询" >
    <input type="button" value="添加投诉"  th:onclick="|add()|">
    </form>
</div>
    <table>
        <tr>
            <th>投诉编号</th>
            <th>投诉品牌</th>
            <th>投诉问题</th>
            <th>投诉车系</th>
            <th>投诉时间</th>
            <th>投诉状态</th>
            <th>投诉操作</th>
        </tr>
        <tr th:each="vs:${vc}">
            <td th:text="${vs.id}"></td>
            <td th:text="${vs.brand.brandName}"></td>
            <td th:text="${vs.problem}"></td>
            <td th:text="${vs.carType}"></td>
            <td th:text="${#dates.format(vs.complaintsTime,'yyyy-MM-dd')}"></td>
            <td th:if="${vs.status==0}">信息审核</td>
            <td th:if="${vs.status==1}">厂家受理</td>
            <td><a href="#" th:onclick="|bianji(${vs.id},${vs.status})|">编辑</a></td>
<!--            src="/veh/toAdd" th:src="|bianji(${vs.id},${vs.status})|"-->
        </tr>
    </table>

</body>
<script th:src="@{https://code.jquery.com/jquery-3.5.1.min.js}" src="js/jquery.js"></script>
<script th:inline="javascript">
    $(document).ready(function(){
        $.ajax({
            type:"GET",
            url:"/selectAll",
            dataType:"json",
            success:function(data){
                //获取model中roleId
                var brandId=[[${brandId}]];
                // alert("json："+data);
                for(var i in data){
                    var op="<option ";
                    if(data[i].brandId==brandId){
                        op+=" selected='selected' ";
                    }
                    op+= " value='"+data[i].brandId+"'>"+data[i].brandName+"</option>";
                    $("#brandId").append(op);
                }
            },
            error:function(data){
                alert("对不起，获取数据失败！");
            }
        });
    });

    function add() {
        location.href="/veh/toAdd";
    }
    function bianji(id,status) {
        if (window.confirm("确认要编辑吗？")) {
            //状态的切换
            if (status == 0) {
                status = 1;
            } else if (status == 1) {
                status = 0;
            }
            $.getJSON("/veh/update?id="+id+"&status="+status, function (data) {
                if (data.reult == true) {
                    alert("修改成功");
                    location.reload();
                } else {
                    alert("修改失败");
                }
            })
        }
    }

</script>
</html>